<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/_all-skins.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/style1.css">
	<script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
	<link rel="stylesheet" media="all" href="${pageContext.request.contextPath}/css/theme1.css" />
	<link rel="stylesheet" media="all" href="${pageContext.request.contextPath}/css/bootstrap.css" />
<style type="text/css">
			#fenye-container{
				margin: 0 auto;
				width:800px;
				height: 60px;
				border:1px solid #888;
				border-radius: 20px;
				display: flex;
				align-items: center;
				font-size: 30px;
				
			}
			
			#fenye-container>div{
				width:40px;
				height: 40px;
				border: 1px solid #888;
				border-radius: 5px;
				margin-left: 20px;
				background: #ccc;
				text-align: center;
				line-height: 40px;
			}
			#fenye-container>div>a{
				color: black;
				text-decoration: none;
			}
		</style>
</head>

<body class="hold-transition skin-red sidebar-mini" >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">商品列表</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                             <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" title="新建" data-toggle="modal" data-target="#editModal" ><i class="fa fa-file-o"></i> 新建</button>
                                        <button type="button" class="btn btn-default" title="删除" onclick="dele()" ><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <div class="box-tools pull-right">
                                <div class="has-feedback">
                                    商品名称：<input >
									<button class="btn btn-default" style="height: 26px;padding: 5px">查询</button>
                                </div>
                            </div>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
			                      <thead>
			                          <tr>
			                              <th class="" style="padding-right:0px">
			                                  <input id="selall" type="checkbox" class="icheckbox_square-blue">
			                              </th> 
										  <th class="sorting_asc">商品ID</th>
										  <th class="sorting">商品图片</th>
									      <th class="sorting">商品名称</th>
									      <th class="sorting">商品价格</th>
									      <th class="sorting">一级分类</th>
									      <th class="sorting">状态</th>									     						
					                      <th class="text-center">操作</th>
			                          </tr>
			                      </thead>
			                      <tbody>
								  <c:if test="${admainname != null}">
			                      <c:forEach items="${goods}" var="p">
			                      		<tr>
			                              <td><input type="checkbox" id="id_${p.ID}"></td>
				                          <td id="gyid">${p.ID }</td>
				                          <td><img src="${pageContext.request.contextPath }/${p.mainPic}" width="40"/></td>
									      <td>${p.productName }</td>
									      <td>${p.maxprice }</td>
									      <td></td>
		
		                                  <td>		                                  
		                                  	<span>
		                                  		${p.state == 1 ? "上架" : "下架"}
		                                  	</span>
		                                  	
		                                  </td>		                                  
		                                  <td class="text-center">                                          
		                                 	  <button type="button" class="btn bg-olive btn-xs" >详情</button>                  
		                                  </td>
			                          </tr>
			                      </c:forEach>
								  </c:if>
								  <c:if test="${admainname== null}">

								  </c:if>
			                          
									 
			                      </tbody>
			                  </table>
			                  
			                  <!--数据列表/-->                        
							  
							 
                        </div>
                        <!-- 数据表格 /-->
						<div class="pagination-wrapper">
							<ul class="pagination">
								<c:if test="${page == 1}">
									<li>
										<a style="background-color: #00a65a" aria-label="Previous">
											<span aria-hidden="true">&laquo;</span>
										</a>
									</li>
								</c:if>
								<c:if test="${page != 1}">
									<li>
										<a style="background-color: #00a65a" href="${pageContext.request.contextPath }/adminservlet?method=show&&page=${page-1}" aria-label="Previous">
											<span aria-hidden="true">&laquo;</span>
										</a>
									</li>
								</c:if>
								<li>
									<a style="background-color: #00a65a" href="#" aria-label="Previous">
										<span aria-hidden="true">${page}</span>
									</a>
								</li>
								<%--<li><a href="#">${pageno}</a></li>--%>
								<li >
									<a style="background-color: #00a65a" href="${pageContext.request.contextPath }/adminservlet?method=show&&page=${page+1}" aria-label="Next">
										<span aria-hidden="true">&raquo;</span>
									</a>
								</li>
							</ul>
						</div>
<%--                        <div id="fenye-container">
							<div id="page-count"><a href="">${pageBean.pageCount }</a></div>
							<div id="total-count"><a href="">${pageBean.totalCount }</a></div>
						</div>--%>
                        
                     </div>
                    <!-- /.box-body -->
 <!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" >
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			<h3 id="myModalLabel">商品添加</h3>
		</div>
		<form id="form1" action="${pageContext.request.contextPath }/picload" method="post"  enctype="multipart/form-data">
			<div class="modal-body">		
				<table class="table table-bordered table-striped"  width="800px">
			      	<tr>
			      		<td>商品名称</td>
			      		<td><input name="productName"  class="form-control" placeholder="商品名称">  </td>
			      	</tr>		      	
			      	<tr>
			      		<td>商品价格</td>
			      		<td><input name="maxprice"  class="form-control" placeholder="商品价格">  </td>
			      	</tr>	
			      	<tr>
			      		<td>商品描述</td>
			      		<td><input name="description"  class="form-control" placeholder="商品描述">  </td>
			      	</tr>	
			      	<tr>
			      		<td>上传图片</td>
			      		<td><input name="mainPic" type="file"  placeholder="商品描述">  </td>
			      	</tr>      	
				 </table>				
			</div>
			<div class="modal-footer">						
				<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" id="saveBtn" style="background-color: #00a65a">保存</button>
				<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
			</div>
		</form>
	  </div>
	</div>
</div>       
</body>
<script type="text/javascript">
$(function(){



	$('#saveBtn').click(function(){
		$('#form1').submit();
	});
})
$('#selall').change(function () {
	var oScid = $('input[id^=id_]');
	if ($(this).prop('checked')) {
		oScid.prop('checked', true);
	} else {
		oScid.prop('checked', false);
	}})
$('input[id^=id_]').change(function(){
	var totalprice = 0;
	//控制全选按钮是否勾选
	if($('input[id^=id_]:not(:checked)').length == 0){
		$('#selall').prop('checked',true);
	}else{
		$('#selall').prop('checked',false);
	}})


function dele() {
	var pa = '${pageContext.request.contextPath }';
		var json=[];
		$('input[id^=id_]:checked').each(function () {
			var gyid=$(this).parent().parent().find('#gyid').text();
			alert(gyid);
			var j = {};
			j.ID=gyid;
			json.push(j)
		});

		var a = JSON.stringify(json);
		console.log(a);
		/*JSON  传值方法*/
		window.location.href = pa + '/adminservlet?method=off&&page=${page}&&jsondata=' + encodeURIComponent(a);




	}
</script>
</html>